﻿using System;
using System.ComponentModel.Composition;

using Warehouse.Service.Data;
using Warehouse.Silverlight.Core.Infrastructure.Events;
using Warehouse.Silverlight.Core.Infrastructure.Models;

namespace Warehouse.Silverlight.Modules.Main.Models
{
    [Export(typeof(IProductFormModel))]
    public class ProductFormModel : Model<ProductionContext>, IProductFormModel
    {

        protected override void Initialize()
        {
            this.Context = ProductionContext.Instance;
        }

        public event EventHandler<EntityResultsArgs<Product>> GetProductByIdComplete;
        public void GetProductByIdAsync(int id)
        {
            PerformEntityQuery<Product>(Context.GetProductByIdQuery(id), GetProductByIdComplete);
        }

        public event EventHandler<EntityResultsArgs<Category>> GetCategoriesComplete;
        public void GetCategoriesAsync()
        {
            PerformEntityQuery<Category>(Context.GetCategoriesQuery(), GetCategoriesComplete);
        }

    }
}
